﻿
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using WWLauncher.Constant;
using WWLauncher.Util;
using WWLauncher.ViewModel;

namespace WWLauncher.Startup
{
    public class Startup
    {

        public Startup()
        {

        }
        public void Start()
        {
            Build();
        }
        /// <summary>
        /// 重建数据
        /// </summary>
        private void Build()
        {
            File.Delete(Constants.DataFilePath);

            MainViewModel appdata = new MainViewModel();
            appdata.MenuList.Clear();
            appdata.MenuList.Add(new MenuViewModel()
            {
                MenuName = "开发",
                MenuType = MenuType.Normal,
                MenuGeometry = "M191.061333 793.344c-47.104 0-87.04 40.106667-87.04 88.832v27.306667c0 21.333333 17.237333 38.656 38.656 38.656h735.061334c21.333333 0 38.741333-17.322667 38.741333-38.741334v-27.221333a85.845333 85.845333 0 0 0-85.674667-88.832H191.061333zM0.426667 596.821333c0 60.416 48.64 110.250667 109.738666 110.250667h803.84c59.221333 0 109.653333-49.834667 109.653334-110.250667V39.509333a38.656 38.656 0 0 0-38.741334-38.741333H39.082667a38.656 38.656 0 0 0-38.656 38.741333v557.226667z m710.314666-332.714666a34.133333 34.133333 0 0 1 0-49.834667c14.336-14.250667 35.925333-14.250667 48.554667 0l125.866667 129.877333a34.133333 34.133333 0 0 1 0 49.834667L759.296 523.861333c-14.421333 14.250667-36.010667 14.250667-48.64 0a34.133333 34.133333 0 0 1 0-49.834666l102.570667-104.96-102.485334-104.96zM440.917333 523.946667L529.066667 189.354667a34.133333 34.133333 0 0 1 43.178666-24.917334c17.92 5.376 28.757333 24.917333 25.173334 44.544l-88.149334 334.506667a34.133333 34.133333 0 0 1-43.093333 24.746667c-19.797333-6.997333-30.549333-26.624-25.173333-44.373334zM293.546667 212.48c14.336-14.165333 35.925333-14.165333 48.554666 0a34.133333 34.133333 0 0 1 0 49.834667l-102.485333 104.96 102.4 104.96a34.133333 34.133333 0 0 1 0 49.834666c-14.336 14.250667-35.84 14.250667-48.469333 0L167.68 392.192a34.133333 34.133333 0 0 1 0-49.834667L293.546667 212.48z",
                MenuId = Guid.NewGuid().ToString(),
            });
            appdata.MenuList.Add(new MenuViewModel()
            {
                MenuName = "测试",
                MenuType = MenuType.Normal,
                MenuGeometry = "M51.609375 820.387187s-6.140623 63.555445 30.703113 101.678477c30.703113 31.777722 85.968717 25.432412 85.968717 25.432412l269.98271-292.34481-110.428864-108.023787-276.225676 273.257708zM610.150177 591.597821L297.131937 280.217081l-6.140622-89.039029-122.761282-76.246065-30.703113 31.828895-36.843736 38.123032-30.651941 31.72655 73.687472 120.765579 79.776922 6.396482 319.107691 317.777223-67.495677 69.900754c98.249963 95.333167 190.256959 197.011644 288.455749 292.344811 98.249963-25.432412 153.464395-95.333167 190.256959-190.666334l-288.45575-292.34481-55.265603 50.813652zM591.728309 483.574034l49.124982-50.864824c98.147619 44.519514 196.346409 25.432412 263.893258-31.72655C972.293399 343.721353 972.293399 229.301084 972.293399 229.301084l-49.124982-19.087102-98.249962 108.074959-159.553846-158.888611 104.390586-108.023787-18.421868-50.864824s-104.390585 0-171.886263 69.900754c-61.406227 63.555445-85.968717 171.579231-36.843736 266.912398l-49.124981 44.519515 98.249962 101.678476z",
                MenuId = Guid.NewGuid().ToString(),
            });

            appdata.MenuList.Add(new MenuViewModel()
            {
                MenuName = "娱乐",
                MenuType = MenuType.Normal,
                MenuGeometry = "M638.6 271.8h-90.1v-71c0-10.7 8.6-19.5 19.2-19.5h80.6c22.1 0 39.9-18.1 39.9-40.5s-17.9-40.5-39.9-40.5h-80.6c-54.7 0-99.1 45.1-99.1 100.4v71h-90C210 271.8 73.3 407.5 73.3 575S210 878.3 378.7 878.3h260C807.3 878.3 944 742.6 944 575c0-167.5-136.7-303.2-305.4-303.2zM416.3 614.6h-52.8v52.8c0 21.9-17.7 39.6-39.6 39.6-21.9 0-39.6-17.7-39.6-39.6v-52.8h-52.8c-21.9 0-39.6-17.7-39.6-39.6 0-21.9 17.7-39.6 39.6-39.6h52.8v-52.8c0-21.9 17.7-39.6 39.6-39.6 21.9 0 39.6 17.7 39.6 39.6v52.8h52.8c21.9 0 39.6 17.7 39.6 39.6 0 21.9-17.7 39.6-39.6 39.6z m250.6-52.7c-21.9 0-39.6-17.7-39.6-39.6 0-21.9 17.7-39.6 39.6-39.6 21.9 0 39.6 17.7 39.6 39.6 0 21.8-17.7 39.6-39.6 39.6z m105.5 105.5c-21.9 0-39.6-17.7-39.6-39.6 0-21.9 17.7-39.6 39.6-39.6 21.9 0 39.6 17.7 39.6 39.6 0 21.9-17.7 39.6-39.6 39.6z",
                MenuId = Guid.NewGuid().ToString(),
            });
            appdata.MenuList.Add(new MenuViewModel()
            {
                MenuName = "应用",
                MenuType = MenuType.Normal,
                MenuId = Guid.NewGuid().ToString(),
            });
            appdata.MenuList.Add(new MenuViewModel()
            {
                MenuName = "AI",
                MenuType = MenuType.Normal,
                MenuGeometry = "M910.2336 1024H113.7664C51.2 1024 0 972.8 0 910.2336V113.7664C0 51.2 51.2 0 113.7664 0h796.4672C972.8 0 1024 51.2 1024 113.7664v796.4672C1024 972.8 972.8 1024 910.2336 1024z m-236.544-242.176l-196.6848-516.352h-71.3472L208.9984 781.824h73.6768l49.664-141.312h215.0144l52.6336 141.312h73.6768z m65.9712 0h65.3568V413.1584h-65.3568V781.824z m-7.68-498.6624c0 11.5456 3.9168 21.1712 11.6992 28.8512 7.7568 7.6544 17.5616 11.4944 29.3376 11.4944 11.776 0 21.6832-3.84 29.824-11.52 8.1152-7.68 12.16-17.28 12.16-28.8256 0-11.776-4.0448-21.5552-12.16-29.312a41.472 41.472 0 0 0-29.824-11.6736c-11.5712 0-21.2992 3.9168-29.184 11.8272a39.6544 39.6544 0 0 0-11.8528 29.184z m-205.312 299.008h-173.3376l77.312-214.6816c3.1232-8.448 5.888-20.4544 8.3456-35.9936h1.6896c2.8672 17.1264 5.5552 29.1072 7.9872 35.9936l78.0032 214.6816z",
                MenuId = Guid.NewGuid().ToString(),
            });
            Trace.WriteLine("重建菜单完成。");
            appdata.MenuList[0].IconList = new();
            foreach (var file in Directory.GetFiles("D:\\Libs\\开发"))
            {
                IconInfo iconInfo = CommonCode.GetIconInfoByPath(file).To();
                appdata.MenuList[0].IconList.Add(iconInfo);
            }
            appdata.MenuList[1].IconList = new();
            foreach (var file in Directory.GetFiles("D:\\Libs\\测试工具"))
            {
                IconInfo iconInfo = CommonCode.GetIconInfoByPath(file).To();
                iconInfo.StartType = IconStartType.AdminStartUp;
                appdata.MenuList[1].IconList.Add(iconInfo);
            }
            appdata.MenuList[2].IconList = new();
            foreach (var file in Directory.GetFiles("D:\\Libs\\娱乐"))
            {
                IconInfo iconInfo = CommonCode.GetIconInfoByPath(file).To();
                appdata.MenuList[2].IconList.Add(iconInfo);
            }
            appdata.MenuList[3].IconList = new();
            foreach (var file in Directory.GetFiles("D:\\Libs\\应用"))
            {
                IconInfo iconInfo = CommonCode.GetIconInfoByPath(file).To();
                appdata.MenuList[3].IconList.Add(iconInfo);
            }
            appdata.MenuList[4].IconList = new();
            foreach (var file in Directory.GetFiles("D:\\Libs\\AI"))
            {
                IconInfo iconInfo = CommonCode.GetIconInfoByPath(file).To();
                iconInfo.StartType = IconStartType.AdminStartUp;
                appdata.MenuList[4].IconList.Add(iconInfo);
            }
            Trace.WriteLine("重建数据完成。");


            appdata.AppConfig.WindowLeft = 300;
            appdata.AppConfig.WindowTop = 300;
            ConfigUtil.SaveAppData(appdata, Constants.DataFilePath);

        }

    }
}